package com.jia.leetCode;

/**
 * @program: Leetcode
 * @description: https://leetcode-cn.com/problems/base-7/submissions/
 * @author: STU756
 * @create: 2020-08-19 13:44
 */
public class Pro0504 {
    public String convertToBase7(int num) {
        StringBuilder sb = new StringBuilder();
        boolean isNegative = false;
        if(num < 0) {isNegative = true; num = -num;}
        long n = (long)num;
        while(n != 0) {
            sb.append(n % 7);
            n /= 7;
        }
        if(sb.length() == 0) sb.append("0");
        if(isNegative) sb.append("-");
        return sb.reverse().toString();
    }
}
